package com.example.lots_of_demo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.lots_of_demo.model.PermissionGroup;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author : LZJ
 * @description : code for LZJ
 * @date : 2021/2/16
 */
public interface PermissionGroupDao extends BaseMapper<PermissionGroup> {

    /**
     * 根据角色ID获取已选择的权限组的ID
     * @param id 权限ID
     * @return List<Integer>
     */
    @Select("SELECT RPR.permission_id FROM ROLE R LEFT JOIN R_ROLE_PERMISSION RRP ON R.ID = RRP.role_id " +
            "LEFT JOIN R_PERMISSION_RES RPR ON RRP.permission_id = RPR.permission_id WHERE R.ID = #{id}")
    List<Integer> getCheckedPermissionGroupByRoleId(Long id);

    /**
     * 根据权限组ID 查找权限组对象包含权限ID
     * @param permissionGroupId 权限组ID
     * @return PermissionGroup
     */
    @Select("SELECT *, P.ID AS PERMISSION_ID FROM PERMISSION_GROUP PG LEFT JOIN PERMISSION P ON PG.PERMISSION_CODE = P.`CODE` WHERE PG.ID = #{permissionGroupId}")
    PermissionGroup selectPermissionGroup(Long permissionGroupId);
}
